package com.shensi.adminCollect.service.markert.impl;

import com.shensi.adminCollect.domain.markert.MarkertPlan;
import com.shensi.adminCollect.mapper.markert.MarkertPlanMapper;
import com.shensi.adminCollect.service.markert.IMarkertPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 营销方案Service业务层处理
 *
 * @author qujia
 * @date 2020-12-22
 */


@Service
public class MarkertPlanServiceImpl implements IMarkertPlanService
{
    @Autowired
    private MarkertPlanMapper markertPlanMapper;

    /**
     * 查询营销方案
     *
     * @param id 营销方案ID
     * @return 营销方案
     */
    @Override
    public MarkertPlan selectMarkertPlanById(Long id)
    {
        return markertPlanMapper.selectMarkertPlanById(id);
    }

    /**
     * 查询营销方案列表
     *
     * @param markertPlan 营销方案
     * @return 营销方案
     */
    @Override
    public List<MarkertPlan> selectMarkertPlanList(MarkertPlan markertPlan)
    {
        return markertPlanMapper.selectMarkertPlanList(markertPlan);
    }

    /**
     * 新增营销方案
     *
     * @param markertPlan 营销方案
     * @return 结果
     */
    @Override
    public int insertMarkertPlan(MarkertPlan markertPlan)
    {
        return markertPlanMapper.insertMarkertPlan(markertPlan);
    }

    /**
     * 修改营销方案
     *
     * @param markertPlan 营销方案
     * @return 结果
     */
    @Override
    public int updateMarkertPlan(MarkertPlan markertPlan)
    {
        return markertPlanMapper.updateMarkertPlan(markertPlan);
    }

    /**
     * 批量删除营销方案
     *
     * @param ids 需要删除的营销方案ID
     * @return 结果
     */
    @Override
    public int deleteMarkertPlanByIds(Long[] ids)
    {
        return markertPlanMapper.deleteMarkertPlanByIds(ids);
    }

    /**
     * 删除营销方案信息
     *
     * @param id 营销方案ID
     * @return 结果
     */
    @Override
    public int deleteMarkertPlanById(Long id)
    {
        return markertPlanMapper.deleteMarkertPlanById(id);
    }

    /**
     * 查询阶梯营销活动
     * @param markertPlan
     * @return
     */
    @Override
    public List<MarkertPlan> searchMarkertPlanList(MarkertPlan markertPlan) {
        List<MarkertPlan> list = markertPlanMapper.searchMarkertPlanList(markertPlan);
        if(list!=null &&  list.size()>0){
            for(MarkertPlan plan:list){
                MarkertPlan markertPlan1 =new MarkertPlan();
                markertPlan1.setOilName(plan.getOilName());
                markertPlan1.setStationId(plan.getStationId());
                markertPlan1.setDiscountPlanType(plan.getDiscountPlanType());
                List<MarkertPlan> planList = markertPlanMapper.selectMarkertPlanList(markertPlan1);
                if(planList!=null && planList.size()>0){
                    plan.setList(planList);
                }
            }
        }
        return list;
    }

    @Override
    public int deleteMarkertPlan(MarkertPlan markertPlan) {
        return markertPlanMapper.deleteMarkertPlan(markertPlan);
    }
}
